﻿@{
    ViewBag.Title = "RepayProject";
    Layout = "~/Views/Shared/_Base.cshtml";
    var curuser = System.Web.HttpContext.Current.User.Identity.Name;
}
@section head{
    <script src="/Content/roohui/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Content/roohui/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="/Content/roohui/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtKey").ligerTextBox({ width: 250 });
            $("#guaranteeCompany").ligerComboBox(
            {
                url: '/GuarCompany/GetGuarCompanyListByKey',
                valueField: 'ID',
                textField: 'CompanyName',
                autocomplete: true,
                width: 180
            });
            $("#product").ligerComboBox(
            {
                url: '/Product/GetProductListByKey',
                valueField: 'ID',
                textField: 'ProductName',
                autocomplete: true,
                width: 180
            });
            $("#txtKey").focus();

            liger.get("guaranteeCompany").setValue("-1");
            liger.get("product").setValue("-1");
        });
    </script>
}
<table cellpadding="0" cellspacing="0" class="l-table-edit">
    <tr>
        <td align="right" class="l-table-edit-td">
            关键字:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="txtKey" ltype="text" ligerui="width:250" style="width: 250;"/>
        </td>
        <td align="right" class="l-table-edit-td">
            产品名称:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="product" ltype="text" ligerui="width:180" style="width:180;"/>
        </td>
        <td align="right" class="l-table-edit-td">
            担保公司:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="guaranteeCompany" ltype="text" ligerui="width:180" style="width:180;"/>
        </td>
        <td align="left" class="l-table-edit-td">
            <input type="button" value="查询" id="btnSearch" onclick="search()" class="l-button" />
        </td>
    </tr>
</table>
<div id="projectgrid">
</div>
<script type="text/javascript">
    var projectgrid;
    $(function () {
        projectgrid = $("#projectgrid").ligerGrid({
            columns: [
                { display: '项目编码', name: 'ProjectCode', width: '8%', isSort: false },
                { display: '项目名称', name: 'ProjectTitle', width: '15%', isSort: false },
                { display: '产品名称', name: 'ProductName', width: '15%', isSort: false },
                { display: '借款企业', name: 'EnterpriseName', width: '15%', isSort: false,
                    render: function (item) {
                        return item.Enterprise.EnterpriseName;
                    }
                },
                { display: '借款金额', name: 'Amount', width: '8%', isSort: false,
                    render: function (item) {
                        return Number(item.Financing / 10000).toFixed(2) + "万元";
                    }
                },
                { display: '借款时长', name: 'Duration', width: '8%', isSort: false,
                    render: function (item) {
                        var durationType = item.Policy.DurationType == 0 ? "天" : "月";
                        return (item.CycleAmount * item.Policy.Duration) + durationType;
                    }
                },
                { display: '担保公司', name: 'CompanyName', width: '10%', isSort: false,
                    render: function (item) {
                        return item.GuaranteeCompany.CompanyName;
                    }
                },

                { display: '状态', name: 'Status', width: '6%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == -1) return '审核不通过';
                        else if (parseInt(item.Status) == 0) return '保存';
                        else if (parseInt(item.Status) == 1) return '提交';
                        else if (parseInt(item.Status) == 2) return '审核中';
                        else if (parseInt(item.Status) == 3) return '审核通过';
                        else if (parseInt(item.Status) == 4) return '已发布';
                        else if (parseInt(item.Status) == 5) return '流标';
                        else if (parseInt(item.Status) == 6) return '满标';
                        else if (parseInt(item.Status) == 7) return '融资成功';
                        else if (parseInt(item.Status) == 8) return '还款中';
                        else if (parseInt(item.Status) == 9) return '完毕';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {
                        var html = '<a href="#" onclick="projectShow(\'' + row.ID + '\', 2)">详情</a>';
                        html = html + '&nbsp;&nbsp;<a href="#" onclick="AccountRest(\'' + row.ID + '\', 1)">借款账户余额</a>';
                           
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Repay/GetRepayProjListByPage",
            pageSizeOptions: [20],
            pageSize: 20
        });

    });

    function search() {
        var guaranteeCompanyID = liger.get("guaranteeCompany").getValue();
        if (guaranteeCompanyID == "") {
            guaranteeCompanyID = "-1";
        }
        var productID = liger.get("product").getValue();
        if (productID == "") {
            productID = "-1";
        }

        projectgrid.setOptions(
             {
                 parms:
                [
                    { name: "key", value: $("#txtKey").val() },
                    { name: "guaranteeCompanyID", value: guaranteeCompanyID },
                    { name: "productID", value: productID },
                    { name: "status", value: statusID },
                    { name: "page", value: 1 }
                ]
             });
        projectgrid.loadData();
    }

    // 修改或详情展示
    function projectShow(projectID, opertype) {
        if (opertype == 1) {
            location.href = decodeURIComponent("/Project/ProjectEdit?projectId=" + projectID);
        }
        else if (opertype == 2) {
            location.href = decodeURIComponent("/Project/ProjectDetails?projectId=" + projectID);
        }
    }


    // 刷新
    function grid_project_refresh() {
        projectgrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
        projectgrid.loadData();
    }
</script>